package com.cn.lyl.servlet.leaving;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.model.LeavingModel;
import com.cn.lyl.model.Page;
import com.cn.lyl.service.LeavingService;
import com.cn.lyl.service.impl.LeavingServiceImpl;
import com.cn.lyl.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/back/leaving/list")
public class FindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String phone = req.getParameter("phone");
        String mail = req.getParameter("mail");
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        LeavingModel leavingModel = new LeavingModel();
        leavingModel.setMail(mail);
        leavingModel.setName(name);
        leavingModel.setPhone(phone);
        leavingModel.setStart(start);
        leavingModel.setEnd(end);
        Page page=new Page();
        page.setPageCurr(Tool.curr(req.getParameter("page")));
        page.setPageSize(Tool.size(req.getParameter("limit")));
        leavingModel.setPage(page);
        LeavingService leavingService = new LeavingServiceImpl();
        JSONObject jsonObject = new JSONObject();
        List<LeavingModel> all = leavingService.findAll(leavingModel);
        jsonObject.put("code",0);
        jsonObject.put("msg","");
        jsonObject.put("count",all.size());
        jsonObject.put("data",all);
        resp.getWriter().print(jsonObject);
    }
}
